package com.zbkj.admin.controller;

import com.zbkj.admin.service.IAdminFileHandleService;
import com.zbkj.common.request.file.AdminFileSaveRequest;
import com.zbkj.common.request.file.AdminFileUpdateRequest;
import com.zbkj.common.response.CommonResult;
import com.zbkj.common.response.file.AdminFileTypeResponse;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/admin/file")
@Api(tags = "服务端-文件管理")
public class AdminFileController {

    @Autowired
    private IAdminFileHandleService adminFileHandleService;

    /**
     * 添加文章
     * @param adminFileSaveRequest
     * @return
     */
    @PostMapping("/adminFileSave")
    public CommonResult adminFileSave(@RequestBody @Validated AdminFileSaveRequest adminFileSaveRequest) {
        adminFileHandleService.adminFileSave(adminFileSaveRequest);
        return CommonResult.success();
    }

    /**
     * 编辑文章
     * @param adminFileUpdateRequest
     * @return
     */
    @PostMapping("/adminFileUpdate")
    public CommonResult adminFileUpdate(@RequestBody @Validated AdminFileUpdateRequest adminFileUpdateRequest) {
        if(adminFileHandleService.adminFileUpdate(adminFileUpdateRequest)){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }
    }

    /**
     * 服务端文件删除
     * @param fileId 文件ID
     * @return
     */
    @GetMapping("/adminFileDel/{fileId}")
    public CommonResult adminFileDel(@PathVariable("fileId") Long fileId) {
        if(adminFileHandleService.adminFileDel(fileId)){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }
    }

    /**
     * 服务端文件类型保存
     * @param fileTypeName 文件类型名称
     * @return
     */
    @GetMapping("/adminFileTypeSave")
    public CommonResult adminFileTypeSave(@RequestParam(value = "fileTypeName") String fileTypeName) {
        if(adminFileHandleService.adminFileTypeSave(fileTypeName)){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }
    }

    /**
     * 服务端文件类型删除
     * @param fileTypeId 文件类型ID
     * @return
     */
    @GetMapping("/adminFileTypeDel/{fileTypeId}")
    public CommonResult adminFileTypeDel(@PathVariable("fileTypeId") Long fileTypeId) {
        if(adminFileHandleService.adminFileTypeDel(fileTypeId)){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }
    }

    /**
     * 服务端文件类型列表
     * @return
     */
    @GetMapping("/adminFileTypeList")
    public CommonResult<List<AdminFileTypeResponse>> adminFileTypeList() {
        return CommonResult.success(adminFileHandleService.adminFileTypeList());
    }

}
